package com.yiyi.user.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.yiyi.common.annotation.Log;
import com.yiyi.common.core.controller.BaseController;
import com.yiyi.common.core.domain.AjaxResult;
import com.yiyi.common.enums.BusinessType;
import com.yiyi.user.domain.SysJson;
import com.yiyi.user.service.ISysJsonService;
import com.yiyi.common.utils.poi.ExcelUtil;
import com.yiyi.common.core.page.TableDataInfo;

/**
 * 测算结果Controller
 *
 * @author yiyi
 * @date 2024-09-26
 */
@RestController
@RequestMapping("/json/json")
public class SysJsonController extends BaseController
{
    @Autowired
    private ISysJsonService sysJsonService;

    /**
     * 查询测算结果列表
     */
    @PreAuthorize("@ss.hasPermi('json:json:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysJson sysJson)
    {
        startPage();
        List<SysJson> list = sysJsonService.selectSysJsonList(sysJson);
        return getDataTable(list);
    }

    /**
     * 导出测算结果列表
     */
    @PreAuthorize("@ss.hasPermi('json:json:export')")
    @Log(title = "测算结果", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysJson sysJson)
    {
        List<SysJson> list = sysJsonService.selectSysJsonList(sysJson);
        ExcelUtil<SysJson> util = new ExcelUtil<SysJson>(SysJson.class);
        util.exportExcel(response, list, "测算结果数据");
    }

    /**
     * 获取测算结果详细信息
     */
    @PreAuthorize("@ss.hasPermi('json:json:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(sysJsonService.selectSysJsonById(id));
    }

    /**
     * 新增测算结果
     */
    @PreAuthorize("@ss.hasPermi('json:json:add')")
    @Log(title = "测算结果", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysJson sysJson)
    {
        return toAjax(sysJsonService.insertSysJson(sysJson));
    }

    /**
     * 修改测算结果
     */
    @PreAuthorize("@ss.hasPermi('json:json:edit')")
    @Log(title = "测算结果", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysJson sysJson)
    {
        return toAjax(sysJsonService.updateSysJson(sysJson));
    }

    /**
     * 根据订单编号修改
     * @param sysJson
     * @return
     */
    @RequestMapping("/updateJsonByOrderNum")
    public AjaxResult updateJsonByOrderNum(@RequestBody SysJson sysJson)
    {
        return toAjax(sysJsonService.updateJsonByOrderNum(sysJson));
    }

    /**
     * 根据订单编获取信息
     * @param sysJson
     * @return
     */
    @RequestMapping("/getJsonByOrderNum")
    public AjaxResult getJsonByOrderNum(SysJson sysJson)
    {
        return success(sysJsonService.getJsonByOrderNum(sysJson));
    }

    /**
     * 删除测算结果
     */
    @PreAuthorize("@ss.hasPermi('json:json:remove')")
    @Log(title = "测算结果", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(sysJsonService.deleteSysJsonByIds(ids));
    }
}
